package generics;

import java.util.ArrayList;

/*
泛型通配符
           <?>:任意类型
           <? extends E>:可以传入E或E的子类
           <? super E>:可以传入E或E的父类
 */
public class GenericsDemo05 {
    public static void main(String[] args) {
        ArrayList<Coder> list1 = new ArrayList<>();
        list1.add(new Coder());

        ArrayList<Manager> list2 = new ArrayList<>();
        list2.add(new Manager());

        method(list1);
        method(list2);
    }
    public static void method(ArrayList<? extends Employee> list){
        for (Object o:list) {
            Employee e = (Employee) o;
            e.work();
        }
    }
}
abstract class Employee{
    private String name;
    private double money;

    public abstract void work();
    public Employee() {
    }

    public Employee(String name, double money) {
        this.name = name;
        this.money = money;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String toString() {
        return "Employee{name = " + name + ", money = " + money + "}";
    }
}
class Coder extends Employee{
    @Override
    public void work() {
        System.out.println("程序员写代码");
    }
}
class Manager extends Employee{

    @Override
    public void work() {
        System.out.println("经理抽烟");
    }
}